from django.urls import reverse
from rest_framework.test import APIClient
from django.db.models import Sum
from play.models import Play
from video.models import Videos
from django.test import TestCase
from user.models import UserProfile
from danmaku.models import Danmaku

class TestDanmakuViewSet(TestCase):
    def setUp(self):
        self.client = APIClient()
        self.user1 = UserProfile.objects.create_user(id=1, username='testuser1', password='123456456')
        self.user2 = UserProfile.objects.create_user(id=2, username='testuser2', password='123456456')
        self.user3 = UserProfile.objects.create_user(id=3, username='testuser3', password='123456456')
        self.video1 = Videos.objects.create(vid=1, title='test1', duration=10, mup=self.user1, type = '1')
        self.video2 = Videos.objects.create(vid=2, title='test2', duration=10, mup=self.user1, type = '2')
        self.video3 = Videos.objects.create(vid=3, title='test3', duration=10, mup=self.user1, type = '2')
        self.danmaku1 = Danmaku.objects.create(id=1, video=self.video1, author=self.user1, text='test1')

    def test_danmaku(self):
        url = reverse('get_danmaku', kwargs={'video':1})
        response = self.client.get(url)
        data = response.json()
        self.assertEqual(data[0]['text'], 'test1')

    def test_danmaku2(self):
        url = reverse('get_danmaku', kwargs={'video':2})
        response = self.client.get(url)
        data = response.json()
        self.assertEqual(data, [])
